<?php
namespace Lisheng\HiAdmin\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use App\User;
use Lisheng\HiAdmin\Models\Permission;
use Hash;
class UserController{

	public function index()
	{
		// $rolelist = Role::get()->toArray();

		// return view('admin.user')->with('rolelist',$rolelist);
		return view('admin.user');
	}

	public function create()
	{
		$permissions = Permission::get()->toArray();

		return view('admin.users.create')->with('permissions',$permissions);;
	}
	
	public function getUserList()
	{
		// $userlist = User::get()->toArray();

		// return view('admin.users')->with('userlist',$userlist);
		return view('admin.users');
	}

	public function postUser(Request $request)
	{
	 // 	$userInfo = $request->only(['name','email','password','role']);

		// $validator = Validator::make($userInfo,[
		// 		'name'=>'required',	
		// 		'password'=>'required',
		// 		'role'=>'required',
		// 		'email'=>'required',
		// 	]);

		// if($validator->fails())
		// {
		// 	return redirect()->back();
		// }

		// try {

		// 	$owner = new User();
		// 	$owner->name         = $userInfo['name'];
		// 	$owner->password = Hash::make($userInfo['password']);
		// 	$owner->email = $userInfo['email'];

		// 	if($owner->save())
		// 	{
		// 		$owner->roles()->attach($owner->id);
		// 		 return redirect(admin_base_path('users'))->with('status', '添加user信息成功');
		// 	}
			
		// } catch (\Exception $e) {
			
		// 		return redirect(admin_base_path('users'))->with('status', '添加user信息失败');
		// }

		
	}
}